code refectoring, not working yet tests..