Small modifications, still needs testing