extensive code cleanup

small optimisations, includedlinter suggestions