ugly code. don't look.