Cleaned up code & added comments describing confusions