better instruction replace logic

fixes #31