bug fixes and test function for main added