Have you checked out Lambdas? Sounds like you may be able to do what you need with that.