Neatened the code and fixed warning messages