Restructure the code with prototypes separated in api.js