improved overall code, fixed some missing ;, incorrect indentations, etc.