Massive overhaul

refactored 75% of the API to reduce controller size and modularise all
functions of the API. This took ages.