Works

but it looks pretty bad.....should try to reduce global variables and
make function calls cleaner