added writeBMP function