Fixing some bugs that were found while using library elsewhere