Decreased ram usage significantly.

Also some misc. changes