Cleaned up syntax and adding more null-checks.