Corrected some bugs. main contains the test used to check bugs