Remove useless statement
Don't directly access resource attributes
Inline some stuff from main I/O loop