Shell clean up

Clean up code and fix bugs on shell