got it working code is a bit sloppy