Rewrote module functions to be entirely recursive and implementation independent