cleaning up and fixing some potential points of failure (because of NullPointerException)