applying devrim's fixes