Rearranged some code.
Added comments and removed debug dumps in the Api module.