Shortened mirabilos' code.