Terrible code, will refactor later.