Mass overhaul - rearrangement, tidying-up, optimization.

Also fixed a few bugs in receiving strings (not finished yet).