Add pascal loop example
Code refactoring and cleanup