Fixed bugs, started writing javadoc