Added function headers.
Added commenting and function header
Added function headers + An error check