major refactor of api backend.. almost works too!