Optimize controll flow
Optimize controll flow, add guards