Fixed CS issues and error handling changed