More efficient code completion + fixed a few bugs