Moved controller code to library, more stuff