major changes to source, credit to linux4kix