code restructured, bugs solved