Final correct code.