APE Refactor and cleanup