Constraints check always delayed scripts 60 seconds

Fixing bugs in the constraints check which always delayed the script 60
seconds. Also includes a bit of code cleaning.