code readability and performance refinements

rather untested, be aware please :)