Buggy but seems to work