Bug fixes+ tests