Fixed a lot of small bugs, introduced internal_id as field in entity