Controlled delivery of pharmaceuticals and bioactive agents