Cleanup of code and added docs