Clean code and fix value checking bugs.