fixed functions and tests..