Reworked code to work