Added check for temporary file
Added switch statement to handle all the actions
Fixed variable name