refactored some code --added support for portal commands