use active record and fix division by 0