Cleanup and add JSDoc comments to functions.