Major refactor to new API