Clean up and comment

Cleaned up and commented code in a proper way