Added/updated tests and fixed various bugs