Added quoting and some refactoring