fixes done. Need testing.
Merge branch 'bugs_562_512' into staging