Clean code and fix bug