Cleaned up and added some documentation