fixes issue #2599 and #2540
fixed some calculation errors
Merge pull request #2635 from FinalAngel/develop

modal size issues