Clean up and optimize framework.{hpp,cpp}