Updated code, try to moduleify a bit better