Refactor and cleanup for 3.0