Fixed the issue with not showing the correct value when data is blank. I
also refactored the code a bit more to make it more readable.