Implemented changes from @Globegitter and issue #41