fixes and refactor structure