Made quite a lot of changes, need to go through them one more time to make this lib consistent