Phase loop cleaned up and tested