Code refactoring; Remove ugly hacks with define, struct access optimization