Reworked code, changed organization