bugfix and restructure