Some modularization and adding prototypes to subs.