cleaning up the code, and added comment blocks on the ApiHandler class