Started big refactoring, with new api lib and templates