Refactor and add mathcheck

> 80-column line