Added JSDoc comments, start refactoring drawing code