added remove method, split up some functionality into their own functions