Changed if statements and finalize code