Avoid to call API functions until LCAPI isn't in a ready state. Also some minor refactoring.