Tested, fixed bugs