Cleaned up and code documented a bit