Few modifications based on lxo's suggestions