better style and more checks