Fixed some bugs with library