(fix)style changes and a bit of error handling