Fixed several bugs, added multiple unit tests

Made changes on most of the files