refactored and windows compatible