Fixed bugs and doing checks for null values when needed.