refactor to not use sys calls