Cleaned up and documented further