added flags + error handling