Clean code and fix R