Fixing errors and tests