Compiled adrianboimvaser's modifications