replaced some awk commands by simpler cut commands
improved code style; made variables local