General clean up and improvments by rafaelcn

Nice job, @rafaelcn.