fix whitespaces and some loops