refactoring for code portabilbity
Fixes #1