Added better messaging and formatted code