Push business logic from /routes to /lib
Add action=count support
Correcting typo