modal fixed and code cleaned up; closes #904; closes #938