Remove POSIX dependency; refactor