Terrible code, lots of room for improvement. Might be useable though.