cleaned up err handling