beginning functions
error checking
added span variable