Implement changes from AOKP branch

See comments for changelog xD