Fix null pointer exception by initialising variables