adding calc-em function & cleaning up