Fixed whitespace and added more checks