code clean-up

removed unneccessary empty lines, inserted empty lines were readability gets improved, removed redundant loop and replaced it by a modulo