settle logic, performance improvement etc

my first pull request