Invalid parameter and possible NullPointerException throwing fixed