added authorization, most logic done
minor formatting edits