Major rewrite of API