original version copied from code forge and orouke's website
modified version for TIPL