Incorporate code review comments

Fix error message
Change the order of if/else