Bugfixes and added jsdoc