Updated code without all the clusterfurick's stuff