Merged in rewrite of core functionality