added stylecop rules, fixed error handling