Cleaned up code, created function prototypes