CLeaned up code