refactors code to be more similar to Github version