More Cleanup. Seperated Code from UI to support merge