Fix some quality issues

Fix some quality issues
Comments and cleanliness issues

Add jsdoc comments, fix a few comments. Clean up some code to make it
more readable.