Refactor to improve extensibility and POSIX compliance