Used local variable scoping for improved readability and modularity. SMB function can now be source directly rather and does not rely on script