magic numbers removed, code finalized