fixing errors and adding tests