finalized version. Loads of changes.