refactored rshell.cpp