Code cleaned up, comments added