Fixed comments
Added resource functions
Fixed matching order
Refactored variable