Code clean up + added more documentation