improved, need to work on algorithm