wow, ugly code, needs lots of work