Refactor and fix entry_points functions.

Seems to be OK with HM now