[fix] internal stage numbering starts at 1
[fix] cleaned up and commented code