Type checking for parameters, general cleanup

Added TypeError exceptions
Updated function definitions to be more clear what the parameters should be
Added shebang header