Ugly code but working