changed module scope to local for performance and encapsulation + some fixes