refactored ApiHandler and JS code to avoid line wrapping