function declarations cleanup, returns cleanup, more error checking