haven't tested new functionality yet, but improving the logic