Fixed some iterator range, added addition checks for safe data usage (to avoid empty values, which causes crashes) and also fixed some code style.