Code was restructured and rewritten