Mod: Code reworked and simplified.