refectored to fix tests