minor restructure + solving bugs