Refactoring to remove dependency on optimist