refactored function space code. working on testing