Various improvements

@kangax:Let me know if you want me to change anything and I will rebase the branch.