some really ugly code, but i'm still working on it