working correctly, in need of more comments