Final working code. frick yeah