Cleaned up code a bit, moved stuff into other methods to make it more readable. Added labels for rwx checks.