Added support for Ad-hoc deployment
Refactoring and error corrections