Commented and cleared code

Made it clearer and got rid of useless code parts.