added code from drozdek