refactored to work in Windows as well