Refectored
Added test