Some fixes and clean code