Fixed bugs when adding a button programmatically