Fix bugs from thrown exceptions

In the drag and drop functions, variables are checked if null before being worked on. This stops exceptions from being thrown and further bugs from happening.