LPS-33812 Fixed bugs, cleaned up code, and source formatting