Refactoring.
Added type checking.
Added functions support.