Small bug fixes and properly dispose internal cache