Attempting to solve null pointer exception