Completely rewrote library