Added tunneling and some refactoring