initial sources from Miroslav Pavleski with minor modifications