Major refactor to work better with API