Tests and small fixes in library