Add tests for loop and fix to work non tail loop start case
Prevent loop code for outside of set function