Fixed code to be PEP8 friendly

Made code more PEP8 friendly and simplified kernel boundary checking
using comparison chaining.