improved coding style and added more const reference parameters