Added compatibility with the SL4A API and rewrote some code