bug fixes in b mattrix swap, change of append function