Memprofile

I needed to import larger files and found out that memory consumption spikes a little. Proposed set of patches solves this (at least partially).

You can see some output from memory profiler on [pastebin](http://pastebin.com/2tKzEdXN) (first is optimized version, later is non-optimized).