Refactor Function class hierarchy into a single class