fix indentation
take mode as parameter, issue #22
rename local var