avoid unnecessary variable assign
formatting
better error handling