Complete restructure and new functions