Updated code to current working state, better code design