Tested code, fixed bugs from last commit.