cleaned & updated code