Various fixes + optimizing graph.subgraph and graph.literal

Hello sho, 

Please review the following commits I made in branch 'jeremy-perf'.

2775c8f7c32f5b84832f8ce3e8c859696855f7b2 (2013-01-31 10:16:30 -0800)
Various fixes + optimizing graph.subgraph and graph.literal

R=sho