fixed scenegraph bugs and refactored a little