final fixes and removed test function