second version - still has bugs