Removed test function. Fixed a possible bug.