Rewrote library to be a bit more flexible